﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" ValidateRequest="false"
    Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content4" ContentPlaceHolderID="script_css" runat="server">
    <link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
    <link href="../../Content/bar.css" rel="stylesheet" type="text/css" />
    <script src="../../Scripts/ckeditor.js" type="text/javascript"></script>
    <script type="text/javascript">
        window.onload = load;
        var date = new Date();
        date.setFullYear(2011, 5, 14);
        function load() {
            setInterval(function () {
                var request = createRequest();
                var hidden = document.getElementById("lid");
                var url = "<%=ViewData["url"].ToString() %>" + "LiveDetailsInfo/GetLiveDetailsByXML";
                try {
                    request.open("POST", url, true);
                    request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                    request.onreadystatechange = function () {
                        if (request.readyState == 4) {
                            if (request.status == 200) {
                                // 返回请求正文
                                parseData(request.responseText);
                            }
                        }
                        return null;
                    };
                    request.send("lasttime=" + date.toLocaleString() + "&liveid=" + hidden.value);
                    //request.send('ajax=1&b=5');通过formcollection接收
                }
                catch (e) { }
            }, 10000);
        }

        function createRequest() {
            var xmlHttp = null;
            try
            {
                // 首先尝试遗留对象
                xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch(e)
            {
                try
                {
                    // 现在尝试ie实现
                    this.xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch (E) {
                    xmlHttp = false;
                }
            }
            if (!xmlHttp && typeof XMLHttpRequest != "undefined") {
                // 因为我们必须使用基于mozilla的浏览器，所以现在创建一个本地请求对象
                xmlHttp = new XMLHttpRequest();
            }
            return xmlHttp;
        }

        function parseData(data) {
            var doc = string2XML(data);
            var nodes = doc.getElementsByTagName("LiveDetails");
            var j = 0;
            var l = nodes.length;
            for(j = 0; j < l; j++)
            {
                addRow(nodes[j].childNodes[3].text, nodes[j].childNodes[2].text);
                date = Date.parse(nodes[j].childNodes[3].text);
            }
        }

        //convert string to xml object
        function string2XML(xmlString) {
            // for IE
            if (window.ActiveXObject) {
                var xmlobject = new ActiveXObject("Microsoft.XMLDOM");
                xmlobject.async = "false";
                xmlobject.loadXML(xmlString);
                return xmlobject;
            }
            // for other browsers
            else {
                var parser = new DOMParser();
                var xmlobject = parser.parseFromString(xmlString, "text/xml");
                return xmlobject;
            }
        }

        //convert xml object to string
        function xml2String(xmlObject) {
            // for IE
            if (window.ActiveXObject) {      
                return xmlObject.xml;
            }
            // for other browsers
            else {       
                return (new XMLSerializer()).serializeToString(xmlObject);
            }
        }

        //动态添加行  
        function addRow(time,con) {  
            var tableNode = document.getElementById("displayTable");  
            if (tableNode) {  
                // 添加一行
                var newTr = tableNode.insertRow();
                // 添加两列
                var newTd0 = newTr.insertCell();
                var newTd1 = newTr.insertCell();
                newTd0.innerText = time;
                newTd1.innerText= con;
            }  
            else {  
                alert("没有找到表格");  
            }  
        }
    </script>
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="categories" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="loginHolder" runat="server">
    <%if (HttpContext.Current.Application["current_user"] != null)
      { %>
    <%Html.RenderPartial("UserStateControl", HttpContext.Current.Application["current_user"]); %>
    <%}
      else
      { %>
    <%=Html.ActionLink("注册", "Register", "User")%>
    <%=Html.ActionLink("登录", "Login", "User") %>
    <%} %>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    直播间
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div>
        <%=Html.Label(((XianboSite.Models.Live)ViewData["live"]).LiveName) %>
        <%=Html.Hidden("lid", ((XianboSite.Models.Live)ViewData["live"]).LiveID, new { id="lid"})%>
    </div>
    <div>
        <table id="displayTable">
        </table>
    </div>
    <%if (HttpContext.Current.Application["current_user"] != null && ((XianboSite.Models.User)HttpContext.Current.Application["current_user"]).UserID == ((XianboSite.Models.Live)ViewData["live"]).UserID)
      { %>
    <%using (Html.BeginForm("CreateDetails", "LiveDetailsInfo"))
      { %>
    <table>
        <tr>
            <td>
            </td>
        </tr>
        <tr>
            <td>
                <%=Html.Hidden("hliveid",((XianboSite.Models.Live)ViewData["live"]).LiveID) %>
                <textarea cols="90" rows="10" id="content" name="content"></textarea>
            </td>
            <td>
                <input type="submit" value="提交" />
            </td>
        </tr>
    </table>
    <script type="text/javascript">
<!--
        CKEDITOR.replace("content",
      {
          skin: "kama", width: 1000, height: 100
      });
//-->
    </script>
    <%} %>
    <% }%>
</asp:Content>
